//https://blog.csdn.net/weixin_36571185/article/details/78140969
layui.define(['layer','jquery'], function(exports) {
	"use strict";

	var $ = layui.jquery,
		layer = layui.layer;

	var user = layui.data('user');
	if(typeof(user)=="undefined" || typeof(user.token)=="undefined")
	{
		layer.msg('请登录',{time: 500}, function () {
		    window.location = rootPath+'login.html';
		});
	}
	$.ajaxSetup({complete:function(xhr,status){
		  layer.closeAll('loading');
		  var data=JSON.parse(xhr.responseText);
	      if(data.code == "401"){
	          layer.msg('请登录',{time: 500}, function () {
	              window.location = rootPath+'login.html';
	          });
	      }else{
	          return data;
	      }
		}
	});
	$.ajaxPrefilter(function( options ) {
		if ( !options.beforeSend) {
			options.beforeSend = function (xhr) { 
				xhr.setRequestHeader('Authorization',"Bearer " + user.token);
			}
		}
		layer.load();
	});
	var auth={
		
	};
    exports("auth", auth);
});